package common;

import dto.TreeNode;

class Solution {

	private static Integer prev = Integer.MIN_VALUE;
	private static boolean isValidBST = true;

	public static void main(String[] args) {
		new Solution().isValidBST(new TreeNode(1).buildTree());
	}
	public boolean isValidBST(TreeNode root) {
		//return isValid(root, null, null);
		if(root == null || (root.left ==null&&root.right==null)) return true;
		inOrder(root);
		return isValidBST;
	}

/*	private boolean isValid(TreeNode root, Integer min, Integer max) {
		if (root == null) return true;
		if (min != null && root.val <= min) return false;
		if (max != null && root.val >= max) return false;
		return isValid(root.left, min, root.val) && isValid(root.right, root.val, max);
	}*/
/*    private boolean isValid(TreeNode root) {
		if(inOrder(root));
    }*/

	private void inOrder(TreeNode root) {
		if (root != null) {
			inOrder(root.left);
			if(root.val < prev){
				isValidBST = false;
				return;
			}
			prev = root.val;
			inOrder(root.right);
		}
	}
}
